package chapter2_10_reSort;

/**
 * @author huayuhao
 * @date 2020/12/16 15:02
 */
public class ResortTest {

    private static boolean ready = false;
    private static int num = 0;

    public static void main(String[] args) throws InterruptedException {
        Thread read = new Thread(()->{
            while(!Thread.currentThread().isInterrupted()){
                if(ready){
                    System.out.println(num+ num);
                }
                System.out.println(" read thread");
            }
        });

        Thread write = new Thread(()-> {
            num = 2;
            ready = true;
            System.out.println("write thread");
        });

        read.start();
        write.start();
        Thread.sleep(10);
        read.interrupt();
        System.out.println("main exit");
    }
}
